package admin

import (
	"github.com/gin-gonic/gin"
	"hzer/internal/mysql"
	"hzer/internal/response"
)

type CreateCardRequestInfo struct {
	MaxBind      int   `json:"max_bind"`      // 最大绑定数
	MaturityTime int64 `json:"maturity_time"` // 到期时间(秒时间戳)
}

func createCard(ctx *gin.Context) {
	reqInfo := CreateCardRequestInfo{}
	if err := ctx.ShouldBindJSON(&reqInfo); err != nil {
		response.FailJson(ctx, response.FailStruct{
			Code: -1,
			Msg:  "Invalid json.",
		}, false)
		return
	}
	// 创建卡
	cradCli := mysql.NewUserCodeInstance()
	code, err := cradCli.AddUserCode(reqInfo.MaxBind, reqInfo.MaturityTime)
	if err != nil {
		response.FailJson(ctx, response.FailStruct{
			Code: -1,
			Msg:  err.Error(),
		}, false)
		return
	}
	response.SuccessJson(ctx, "success", gin.H{
		"code": code,
	})
}
